/*
 * function.c
 *
 *  Created on: 2013-5-15
 *      Author: xkaying
 */

#include "function.h"
#include "../common/list.h"
#include "../typedef/prority.h"

#include <assert.h>

typedef struct _functionitem{
		int type;
		char *value;
		char *ctype;
		char *name;
}FunctionItem;

struct _function{
		int type; //0表示普通function 1表示operator.
		//函数开放程度
		int prority;
		int isfinal;
		int isinline;
		char *name;
		List *input;
		char *output;
		//函数语句
		List *content;
};

char *FunctionName(Function *pfun)
{
	assert(pfun);
	return pfun->name;
}

void FunctionAppendInput(Function *pfun,char *ctype,char *name,int type,char *value)
{
	assert(pfun);
	assert(type);
	FunctionItem *pitem;
	pitem=(FunctionItem*)malloc(sizeof(FunctionItem));
	pitem->type=type;
	pitem->name=name;
	pitem->ctype=ctype;
	pitem->value=value;
	if(pfun->input==0){
		pfun->input=ListInit();
	}
	ListPush(pfun->input,pfun);
}

int FunctionIsempty(Function *pfun)
{
	assert(pfun);
	if(pfun->content==0){
		return 1;
	}
	return 0;
}

int FunctionNameCompare(Function *psrc,Function *pdest)
{
	assert(psrc);
	assert(pdest);
	return psrc->name==pdest->name;
}

void FunctionAppendName(Function *pfun,char *name)
{
	assert(pfun);
	pfun->name=name;
}

Function *FOperatorInit(int isinline)
{
	Function *pfun;
	pfun=(Function*)malloc(sizeof(Function));
	pfun->type=1;
	pfun->prority=Prority_Public;
	pfun->isfinal=0;
	pfun->isinline=isinline;
	pfun->name=0;
	pfun->input=0;
	pfun->output=0;
	pfun->content=0;
	return pfun;
}

Function *FunctionInit(int prority,int isfinal,int isinline)
{
	Function *pfun;
	pfun=(Function*)malloc(sizeof(Function));
	pfun->type=0;
	pfun->prority=prority;
	pfun->isfinal=isfinal;
	pfun->isinline=isinline;
	pfun->name=0;
	pfun->input=0;
	pfun->output=0;
	pfun->content=0;
	return pfun;
}
